var shopId = GetQueryString("shopId");
var userId = GetQueryString("userId");

if(!shopId || !userId){
    window.history.back(-1);
}
$(function () {
    selectMyShop()   //查询店铺信息
    getShopUse() ;   //加载常用功能页面
})

function selectMyShop() {
    $.get(getWeiContextPath() + "/wx/shop/selectOneShop", {shopId: shopId}, function (res) {
        console.log(res)
        $(".userNickName").text(res.wxShop.shopName)
        $(".wxUserId").text(res.wxShop.wxUserId)
        $(".phone").text(res.wxShop.shopTel)
        $(".shopMoney").text(res.wxShop.shopMoney)
        if (res.wxShop.logoImgs.length>0){
            $(".userAvatarUrl").attr("src",getImgSrc(res.wxShop.logoImgs[0].imgPath))
        }
        $(".vipCount").text(res.vipCount)
        $(".collectionCount").text(res.collectCount)
    })
}


function getShopUse() {
    $('.merchant-top').html('<a href="javascript:void(0)">\n' +
        '            <div class="cl-main vipCount" ></div>\n' +
        '            <div>会员总数</div>\n' +
        '        </a>\n' +
        '        <a href="javascript:void(0)" onclick="toPick()">\n' +
        '            <div class="cl-main shopMoney"></div>\n' +
        '            <div>账户余额</div>\n' +
        '        </a>\n' +
        '        <a href="javascript:void(0)">\n' +
        '            <div class="cl-main collectionCount"></div>\n' +
        '            <div>收藏人数</div>\n' +
        '        </a>')
    var str;
    $.ajax({
        type: "POST",
        cache: false,
        data: {shopId:shopId},
        async: false,
        url: getWeiContextPath()+"/wx/shop/myMessageCount",
        success: function (res) {
            str ='<a href="shop-news.html?shopId='+shopId+'" class="weui_grid js_grid" style="position: relative;">\n' +
                '            <span class="weui-badge" style="position: absolute;top:0;right:15px;">'+res+'</span>\n' +
                '            <div class="weui_grid_icon">\n' +
                '                <img style="width:24px;height:24px;" src="../images/xiaoxi11.png" alt="">\n' +
                '            </div>\n' +
                '            <p class="weui_grid_label">\n' +
                '                店铺消息\n' +
                '            </p>\n' +
                '        </a>'
        },
    });

    $('.oldUse').html('<a href="javascript:void(0)" class="weui_grid js_grid" onclick="toBankList()">\n' +
        '            <div class="weui_grid_icon">\n' +
        '                <i class="iconfont icon-yinhangqia1"></i>\n' +
        '            </div>\n' +
        '            <p class="weui_grid_label">\n' +
        '                银行卡\n' +
        '            </p>\n' +
        '        </a>\n' +
        '        <a href="user_list.html?shopId='+shopId+'" class="weui_grid js_grid">\n' +
        '            <div class="weui_grid_icon">\n' +
        '                <i class="iconfont icon-huiyuanliebiao"></i>\n' +
        '            </div>\n' +
        '            <p class="weui_grid_label">\n' +
        '                会员列表\n' +
        '            </p>\n' +
        '        </a>' +str+
        '')

    $('.shopOrder').html('<a href="order_manage.html?shopId='+shopId+'" class="weui_grid js_grid">\n' +
        '            <div class="weui_grid_icon">\n' +
        '                <i class="iconfont icon-dingdan2"></i>\n' +
        '            </div>\n' +
        '            <p class="weui_grid_label">\n' +
        '                门店订单\n' +
        '            </p>\n' +
        '        </a>' +
        '<a href="bill_collection.html?shopId='+shopId+'" class="weui_grid js_grid">\n' +
        '            <div class="weui_grid_icon">\n' +
        '                <i class="iconfont icon-yishoukuan"></i>\n' +
        '            </div>\n' +
        '            <p class="weui_grid_label">\n' +
        '                收款账单\n' +
        '            </p>\n' +
        '        </a>'+
        '<a href="returnOrder.html?shopId='+shopId+'" class="weui_grid js_grid">\n' +
        '            <div class="weui_grid_icon">\n' +
        '                <i class="iconfont icon-tongji"></i>\n' +
        '            </div>\n' +
        '            <p class="weui_grid_label">\n' +
        '                返利账单\n' +
        '            </p>\n' +
        '        </a>')
}
/*去提现页面*/
function toPick() {
    var shopUserId =$(".wxUserId").text();
    if (shopUserId==userId){
        window.location.href ='withdrawal.html?shopId='+shopId
    }else {
        $.toast("权限不足", "forbidden");
    }

}
/*去查看绑定银行卡页面*/
function toBankList() {
    var shopUserId =$(".wxUserId").text();
    if (shopUserId==userId){
        window.location.href ='bank_list.html?shopId='+shopId
    }else {
        $.toast("权限不足", "forbidden");
    }
}
